


public class BoxOnGoalRule implements MoveRule 
{
	
	private boolean[][] visitable;
	
	public BoxOnGoalRule( boolean[][] visitable )
	{
		this.visitable = visitable;
	}

	@Override
	public boolean isLegalMove(Board board, Move move, Move.Direction direction) 
	{
		boolean value = true;
		
		if ( !board.getCellType( move.doNewMove( direction.reverse() ) ).isBox() )
		{
			throw new RuntimeException("Bug i Olles kod igen!");
		}
		
		Move movePlus = move.doNewMove(direction);
		
		value &= board.getCellType( move ).notWallOrBox();
		value &= board.getCellType( movePlus ).notWallOrBox();
		
		value &= visitable[ movePlus.getX() ][ movePlus.getY() ];

		return value;
	}

}
